home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 9VBFAT (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.4 KB  |  75 lines

  1. package com.sun.java.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.LayoutManager;
  7. import java.awt.Point;
  8. import java.io.Serializable;
  9.  
  10. public class ViewportLayout implements LayoutManager, Serializable {
  11.    public void addLayoutComponent(String name, Component c) {
  12.    }
  13.  
  14.    public void layoutContainer(Container parent) {
  15.       JViewport vp = (JViewport)parent;
  16.       Component view = vp.getView();
  17.       Scrollable scrollableView = null;
  18.       if (view != null) {
  19.          if (view instanceof Scrollable) {
  20.             scrollableView = (Scrollable)view;
  21.          }
  22.  
  23.          vp.getInsets();
  24.          Dimension viewPrefSize = view.getPreferredSize();
  25.          Dimension vpSize = ((Component)vp).getSize();
  26.          Dimension extentSize = vp.toViewCoordinates(vpSize);
  27.          if (scrollableView != null) {
  28.             if (scrollableView.getScrollableTracksViewportWidth()) {
  29.                viewPrefSize.width = vpSize.width;
  30.             }
  31.  
  32.             if (scrollableView.getScrollableTracksViewportHeight()) {
  33.                viewPrefSize.height = vpSize.height;
  34.             }
  35.          }
  36.  
  37.          Point viewPosition = vp.getViewPosition();
  38.          if (viewPosition.y + extentSize.height > viewPrefSize.height) {
  39.             viewPosition.y = 0;
  40.          }
  41.  
  42.          if (viewPosition.x + extentSize.width > viewPrefSize.width) {
  43.             viewPosition.x = 0;
  44.          }
  45.  
  46.          if (viewPosition.y == 0 && vpSize.height > viewPrefSize.height) {
  47.             viewPrefSize.height = vpSize.height;
  48.          }
  49.  
  50.          if (viewPosition.x == 0 && vpSize.width > viewPrefSize.width) {
  51.             viewPrefSize.width = vpSize.width;
  52.          }
  53.  
  54.          vp.setViewPosition(viewPosition);
  55.          vp.setViewSize(viewPrefSize);
  56.       }
  57.    }
  58.  
  59.    public Dimension minimumLayoutSize(Container parent) {
  60.       return new Dimension(4, 4);
  61.    }
  62.  
  63.    public Dimension preferredLayoutSize(Container parent) {
  64.       Component view = ((JViewport)parent).getView();
  65.       if (view == null) {
  66.          return new Dimension(0, 0);
  67.       } else {
  68.          return view instanceof Scrollable ? ((Scrollable)view).getPreferredScrollableViewportSize() : view.getPreferredSize();
  69.       }
  70.    }
  71.  
  72.    public void removeLayoutComponent(Component c) {
  73.    }
  74. }
  75.